// https://leetcode.cn/problems/path-sum/
// Created by ade on 2022/7/19.
//

#include <iostream>
#include <vector>


using namespace std;

struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;

    TreeNode() : val(0), left(nullptr), right(nullptr) {}

    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}

    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};

class Solution {
public:
    bool flag = false;

    bool hasPathSum(TreeNode *root, int targetSum) {
        dfs(root, 0, targetSum);
        return flag;
    }

    void dfs(TreeNode *node, int tmp, int targetSum) {
        if (node) {
            if (!node->left && !node->right && tmp + node->val == targetSum) {
                flag = true;
                return;
            }
            dfs(node->left, tmp + node->val, targetSum);
            dfs(node->right, tmp + node->val, targetSum);
        }

    }
};

int main() {
    Solution so;
    TreeNode *head = so.init();
    auto res = so.hasPathSum(head);
    if (res) {
        cout << "yes" << endl;
    } else {
        cout << "no" << endl;
    }
    return 0;
}